<?php

class AdminController extends Zend_Controller_Action
{
 public function init()
    {

         $this->_flashMessenger = new Lib_Flash();
        $this->_helper->layout()->setLayout('admin-layout');

    }

    public function indexAction()
    {
        $usersession = new \Zend_Session_Namespace("usersession");


          if (!($usersession->general=="generalisimus")){

              $this->_redirect('/getin');
          }
    }
    public function clearAction()
    {

        $manager = new \Managers\BaseManager();
        $manager->_getCacheManager()->clean();
        $this->_flashMessenger->addMessage('Cache successfully cleared.', Lib_Flash::NOTICE, Lib_Flash::PRE);
        $this->_redirect('/admin');
    }
    public function getinAction()
    {
        $this->_helper->layout()->setLayout('login');

        if ($this->_request->isPost()) {

        $login = $this->_getParam("login");
        $pass = $this->_getParam("pass");
        $authManeger=new Managers\Auth();
        $user= $authManeger->getUser($login,md5($pass));
            if ($user)

            {
                $usersession = new \Zend_Session_Namespace("usersession");
                $usersession->general="generalisimus";
                $this->_redirect('/admin');
            }
            else {    $this->_flashMessenger->addMessage('Login or password do not match', Lib_Flash::ERROR, Lib_Flash::PRE);}

        }


    }
    public function exitAction(){
        $usersession = new \Zend_Session_Namespace("usersession");
        $usersession->general="";
        $this->_redirect('/admin');

    }
}